package cn.lingyangwl.boot.modules;

import cn.lingyangwl.agile.system.model.entity.SysDept;
import cn.lingyangwl.agile.system.model.entity.SysUser;
import cn.lingyangwl.framework.tool.core.ObjectUtils;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * bean 和 map转换测试
 * @author shenguangyang
 */
public class BeanMapIConfigListenerPayload {

    @Test
    public void test() throws Exception {
        List<SysDept> sysDeptList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            SysDept sysDept = new SysDept();
            sysDept.setEmail("shenguangyang@foxmail.com");
            sysDept.setDeptName("shenguangyang@foxmail.com");
            sysDept.setParentId(12L);
            sysDeptList.add(sysDept);
        }
        for (int j = 0; j < 15; j++) {
            new Thread(() -> {
                try {
                    long t1 = System.currentTimeMillis();
                    for (int i = 0; i < 1000; i++) {
                        SysUser sysUser = new SysUser();
                        sysUser.setUserId(12L);
                        sysUser.setLastLoginIp("127.0.0.1");
                        sysUser.setEmail("shenguangyang@foxmail.com");
                        sysUser.setUserName("admin");
                        Map<String, Object> stringObjectMap = ObjectUtils.beanToMap(sysDeptList);
                    }
                    long t2 = System.currentTimeMillis();
                    System.out.println("time: " + (t2 - t1) + " ms");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }).start();
        }

        TimeUnit.SECONDS.sleep(5);
    }
}
